home *** CD-ROM | disk | FTP | other *** search
- /*
- File: TextEditorPrefs.cpp
-
- Contains: TextEditor Preference dialog functions
-
- Written by: Steve Smith
-
- Copyright: © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
- */
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _EXCEPT_
- // Exceptions define several important macros (e.g. CHECKENV)
- // which are used in the SOM method dispatch glue. If Except.h
- // is not included early enough, exceptions may not be thrown
- // correctly when returning from a SOM method with "ev" parameter set.
- #include <Except.h>
- #endif
-
- // --- TextEditor Includes ---
-
- #ifndef _TEXTEDITORSETTINGS_
- #include "TextEditorSettings.h"
- #endif
-
- #ifndef _TEXTEDITORUTILS_
- #include "TextEditorUtils.h"
- #endif
-
- #ifndef _TEXTEDITORDEF_
- #include "TextEditorDef.h"
- #endif
-
- #ifndef _STDTEXTPROPERTIES_
- #include "StdTextProps.h"
- #endif
-
- #ifndef _TEXTEDITORGLOBALS_
- #include "TextEditorGlobals.h"
- #endif
-
- // --- OpenDoc Includes ---
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Foci_defined
- #include <Foci.xh>
- #endif
-
- // --- Unsupported Utilities
-
- #ifndef _BARRAY_
- #include "BArray.h"
- #endif
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h"
- #endif
-
- #ifndef _USERSRCM_
- #include "UseRsrcM.h"
- #endif
-
- #ifndef _DLOGUTIL_
- #include "DlogUtil.h"
- #endif
-
- // --- Macintosh Includes ---
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef mathRoutinesIncludes
- #include <math routines.h>
- #endif
-
- #ifndef __FP__
- #include <fp.h>
- #endif
-
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- #ifndef __OSUTILS__
- #include <OSUtils.h>
- #endif
-
- #ifndef __SCRIPT__
- #include <Script.h>
- #endif
-
- #ifndef __FOLDERS__
- #include <Folders.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- // --- Textension Includes ---
-
- #ifndef _RulerObject_
- #include <RulerObject.h>
- #endif
-
-
- #pragma segment TextEditorSettings
-
-
- //------------------------------------------------------------------------------
- // ModalSettingsDialog
- //------------------------------------------------------------------------------
-
- void ModalSettingsDialog( Environment* ev, ODFrame* frame, Rect* margins,
- ODUShort* alignment )
- {
- const ODUShort kLeftAlignButton = 3;
- const ODUShort kRightAlignButton = 4;
- const ODUShort kCenterAlignButton = 5;
- const ODUShort kJustifiedAlignButton = 6;
- const ODUShort kTopMarginField = 7;
- const ODUShort kLeftMarginField = 8;
- const ODUShort kBottomMarginField = 9;
- const ODUShort kRightMarginField = 10;
-
- TempODPart tPart = frame->AcquirePart(ev);
- ODSession* session = ODGetSession(ev, tPart);
-
- // Our About box is modal so we must request the Modal focus to prevent
- // multiple modal dialogs being displayed simultaneously.
-
- if ( session->GetArbitrator(ev)->RequestFocus(ev, gGlobals->fModalFocus,frame) )
- {
- ODSShort itemHit;
- short iType;
- Handle iHandle;
- Rect iRect;
- Str255 strValue;
- short currentAlignment;
-
- CUsingLibraryResources res;
-
- session->GetWindowState(ev)->DeactivateFrontWindows(ev);
- // Dim the frontmost document window.
-
- ODBoolean hasMarginItems = frame->IsRoot(ev);
- ODSShort dlogID = hasMarginItems ? kSettingsDialogID : kSettingsNoMarginsDialogID;
- DialogPtr dialog = GetNewDialog(dlogID, kODNULL, (WindowPtr)-1L);
-
- // Set dialog font and other std things.
- SetDialogDefaults(dialog, kDialogFontInfoID, kSettingsFontIndex);
-
- // Stuff current margins into dialog fields
- if (hasMarginItems)
- {
- GetDialogItem(dialog, kTopMarginField, &iType, &iHandle, &iRect);
- ConvertPixelsToNumStr(margins->top, &strValue);
- SetDialogItemText(iHandle, strValue);
-
- GetDialogItem(dialog, kLeftMarginField, &iType, &iHandle, &iRect);
- ConvertPixelsToNumStr(margins->left, &strValue);
- SetDialogItemText(iHandle, strValue);
-
- GetDialogItem(dialog, kBottomMarginField, &iType, &iHandle, &iRect);
- ConvertPixelsToNumStr(margins->bottom, &strValue);
- SetDialogItemText(iHandle, strValue);
-
- GetDialogItem(dialog, kRightMarginField, &iType, &iHandle, &iRect);
- ConvertPixelsToNumStr(margins->right, &strValue);
- SetDialogItemText(iHandle, strValue);
- }
-
- // Set the appropriate radio button for the current justification
- switch ( *alignment )
- {
- case left: currentAlignment = kLeftAlignButton; break;
- case center: currentAlignment = kCenterAlignButton; break;
- case right: currentAlignment = kRightAlignButton; break;
- case fulljustification: currentAlignment = kJustifiedAlignButton; break;
- }
-
- GetDialogItem(dialog, currentAlignment, &iType, &iHandle, &iRect);
- SetControlValue((ControlHandle) iHandle, 1);
-
- ShowWindow(dialog);
-
- ModalFilterUPP otherDialogProc = NewModalFilterProc(OtherDialogFilter);
-
- // Select the text in the top margin field
- SelectDialogItemText(dialog, kTopMarginField, 0, 32767);
-
- do
- {
- ModalDialog(kODNULL, &itemHit);
-
- switch (itemHit)
- {
- case kLeftAlignButton:
- case kCenterAlignButton:
- case kRightAlignButton:
- case kJustifiedAlignButton:
- GetDialogItem(dialog, kLeftAlignButton, &iType, &iHandle, &iRect);
- SetControlValue((ControlHandle) iHandle, (itemHit == kLeftAlignButton));
-
- GetDialogItem(dialog, kCenterAlignButton, &iType, &iHandle, &iRect);
- SetControlValue((ControlHandle) iHandle, (itemHit == kCenterAlignButton));
-
- GetDialogItem(dialog, kRightAlignButton, &iType, &iHandle, &iRect);
- SetControlValue((ControlHandle) iHandle, (itemHit == kRightAlignButton));
-
- GetDialogItem(dialog, kJustifiedAlignButton, &iType, &iHandle, &iRect);
- SetControlValue((ControlHandle) iHandle, (itemHit == kJustifiedAlignButton));
- break;
- }
- }
- while ( itemHit != ok && itemHit != cancel );
-
- DisposeRoutineDescriptor(otherDialogProc);
-
- if ( itemHit == ok )
- {
- // retrieve the "new" margins settings
-
- if ( hasMarginItems )
- {
- GetDialogItem(dialog, kTopMarginField, &iType, &iHandle, &iRect);
- GetDialogItemText(iHandle, strValue);
- margins->top = ConvertNumStrToPixels(strValue);
-
- GetDialogItem(dialog, kLeftMarginField, &iType, &iHandle, &iRect);
- GetDialogItemText(iHandle, strValue);
- margins->left = ConvertNumStrToPixels(strValue);
-
- GetDialogItem(dialog, kBottomMarginField, &iType, &iHandle, &iRect);
- GetDialogItemText(iHandle, strValue);
- margins->bottom = ConvertNumStrToPixels(strValue);
-
- GetDialogItem(dialog, kRightMarginField, &iType, &iHandle, &iRect);
- GetDialogItemText(iHandle, strValue);
- margins->right = ConvertNumStrToPixels(strValue);
- }
-
- // retrieve the "new" alignment setting
-
- GetDialogItem(dialog, kLeftAlignButton, &iType, &iHandle, &iRect);
- *alignment = GetControlValue((ControlHandle) iHandle) ? left : *alignment;
- GetDialogItem(dialog, kCenterAlignButton, &iType, &iHandle, &iRect);
- *alignment = GetControlValue((ControlHandle) iHandle) ? center : *alignment;
- GetDialogItem(dialog, kRightAlignButton, &iType, &iHandle, &iRect);
- *alignment = GetControlValue((ControlHandle) iHandle) ? right : *alignment;
- GetDialogItem(dialog, kJustifiedAlignButton, &iType, &iHandle, &iRect);
- *alignment = GetControlValue((ControlHandle) iHandle) ? fulljustification : *alignment;
- }
-
- DisposeDialog(dialog);
-
- session->GetArbitrator(ev)->RelinquishFocus(ev, gGlobals->fModalFocus, frame);
- // Inform the Arbitrator that we no longer require the Modal focus.
-
- session->GetWindowState(ev)->ActivateFrontWindows(ev);
- // Hilite the frontmost document window.
- }
- }
-
-
-